home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / edit / TSMrph23s.lha / TSM23s.lha / HandleSettings.c < prev    next >
C/C++ Source or Header  |  1993-10-08  |  25KB  |  845 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. //    $Author: M_J_Paddock $
  21. //    $Date: 1993/09/04 17:45:18 $
  22. //    $Revision: 1.10 $
  23.  
  24. // include precompiled headers (if not already)
  25. #ifndef TSMORPH_H
  26. #include "TSMorph.h"
  27. #endif
  28.  
  29. /* Remove menus from all windows allowing
  30.  * them to be updated
  31.  */
  32. void
  33. RemoveMenus(void) {
  34.     if (TSMorphWnd) {
  35.         ClearMenuStrip(TSMorphWnd);
  36.     }
  37.     if (ControlWindow) {
  38.         ClearMenuStrip(Pic1.Win);
  39.         ClearMenuStrip(Pic2.Win);
  40.         ClearMenuStrip(ControlWindow);
  41.     }
  42. }
  43.  
  44. /* Add the menus back again after
  45.  * calling RemoveMenus() and updating
  46.  */
  47. void
  48. AddMenus(void) {
  49.     if (TSMorphWnd) {
  50.         ResetMenuStrip(TSMorphWnd,TSMorphMenus);
  51.     }
  52.     if (ControlWindow) {
  53.         ResetMenuStrip(ControlWindow,MyMenu);
  54.         ResetMenuStrip(Pic1.Win,MyMenu);
  55.         ResetMenuStrip(Pic2.Win,MyMenu);
  56.     }
  57. }
  58.  
  59. /* Update the save format menu items
  60.  * Parameter: remove - set to TRUE to remove and add the menus
  61.  *                         to FALSE if menus have already been removed (for lots of updates)
  62.  */
  63. void
  64. UpdateSaveFormat(BOOL remove) {
  65.     if (remove) {
  66.         RemoveMenus();
  67.     }
  68.     if (TSMorphWnd) {
  69.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_ILBM24)))->Flags &= ~CHECKED;
  70.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24)))->Flags &= ~CHECKED;
  71.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24T)))->Flags &= ~CHECKED;
  72.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24F)))->Flags &= ~CHECKED;
  73.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_OPAL24FT)))->Flags &= ~CHECKED;
  74.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_JPEG)))->Flags &= ~CHECKED;
  75.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_JPEGT)))->Flags &= ~CHECKED;
  76.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_PBM)))->Flags &= ~CHECKED;
  77.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_BW16)))->Flags &= ~CHECKED;
  78.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_BW256)))->Flags &= ~CHECKED;
  79.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_HAM6)))->Flags &= ~CHECKED;
  80.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_HAM8)))->Flags &= ~CHECKED;
  81.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_DCTV3)))->Flags &= ~CHECKED;
  82.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,MI_DCTV4)))->Flags &= ~CHECKED;
  83.     }
  84.     if (ControlWindow) {
  85.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_ILBM24)))->Flags &= ~CHECKED;
  86.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24)))->Flags &= ~CHECKED;
  87.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24T)))->Flags &= ~CHECKED;
  88.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24F)))->Flags &= ~CHECKED;
  89.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_OPAL24FT)))->Flags &= ~CHECKED;
  90.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_JPEG)))->Flags &= ~CHECKED;
  91.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_JPEGT)))->Flags &= ~CHECKED;
  92.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_PBM)))->Flags &= ~CHECKED;
  93.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_BW16)))->Flags &= ~CHECKED;
  94.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_BW256)))->Flags &= ~CHECKED;
  95.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_HAM6)))->Flags &= ~CHECKED;
  96.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_HAM8)))->Flags &= ~CHECKED;
  97.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_DCTV3)))->Flags &= ~CHECKED;
  98.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,MI_DCTV4)))->Flags &= ~CHECKED;
  99.     }
  100.     if (TSMorphWnd) {
  101.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_SAVEFORMAT,SaveFormat)))->Flags |= CHECKED;
  102.     }
  103.     if (ControlWindow) {
  104.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_SAVEFORMAT,SaveFormat)))->Flags |= CHECKED;
  105.     }
  106.     if (remove) {
  107.         AddMenus();
  108.     }
  109. }
  110.  
  111. /* Update the render mode menu items
  112.  * see UpdateSaveFormat() for parameter
  113.  */
  114. void
  115. UpdateRenderMode(BOOL remove) {
  116.     if (remove) {
  117.         RemoveMenus();
  118.     }
  119.     if (TSMorphWnd) {
  120.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE0)))->Flags &= ~CHECKED;
  121.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE1)))->Flags &= ~CHECKED;
  122.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE2)))->Flags &= ~CHECKED;
  123.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,MI_MODE3)))->Flags &= ~CHECKED;
  124.     }
  125.     if (ControlWindow) {
  126.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE0)))->Flags &= ~CHECKED;
  127.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE1)))->Flags &= ~CHECKED;
  128.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE2)))->Flags &= ~CHECKED;
  129.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,MI_MODE3)))->Flags &= ~CHECKED;
  130.     }
  131.     if (TSMorphWnd) {
  132.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_RENDERMODE,RenderMode)))->Flags |= CHECKED;
  133.     }
  134.     if (ControlWindow) {
  135.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_RENDERMODE,RenderMode)))->Flags |= CHECKED;
  136.     }
  137.     if (remove) {
  138.         AddMenus();
  139.     }
  140. }
  141.  
  142. /* Update the open mode menu items
  143.  * see UpdateSaveFormat() for parameter
  144.  */
  145. void
  146. UpdateOpenMode(BOOL remove) {
  147.     if (remove) {
  148.         RemoveMenus();
  149.     }
  150.     if (TSMorphWnd) {
  151.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_ALWAYS)))->Flags &= ~CHECKED;
  152.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_IFILBM)))->Flags &= ~CHECKED;
  153.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_IFCOLOURS)))->Flags &= ~CHECKED;
  154.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_REMAP)))->Flags &= ~CHECKED;
  155.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,MI_OPAL)))->Flags &= ~CHECKED;
  156.     }
  157.     if (ControlWindow) {
  158.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_ALWAYS)))->Flags &= ~CHECKED;
  159.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_IFILBM)))->Flags &= ~CHECKED;
  160.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_IFCOLOURS)))->Flags &= ~CHECKED;
  161.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_REMAP)))->Flags &= ~CHECKED;
  162.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,MI_OPAL)))->Flags &= ~CHECKED;
  163.     }
  164.     if (TSMorphWnd) {
  165.         (ItemAddress(TSMorphMenus,FULLMENUNUM(1,MM_OPENMODE,OpenMode)))->Flags |= CHECKED;
  166.     }
  167.     if (ControlWindow) {
  168.         (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,MM_OPENMODE,OpenMode)))->Flags |= CHECKED;
  169.     }
  170.     if (remove) {
  171.         AddMenus();
  172.     }
  173. }
  174.  
  175. /* UnZoom the image windows
  176.  * i.e. currently displayed 2x and
  177.  * want to display 1x
  178.  */
  179. void
  180. UnZoom(void) {
  181.     // Already zoomed - set number of windows resized (change window box may not work)
  182.     // see the main loop on how the messages are then handled
  183.     changedboxcount = 0;
  184.     // Copy image 1 to superbitmap and resync
  185.     BltBitMap(Pic1.ilbm->brbitmap,0,0,&(Pic1.BitMap),0,0,Pic1.ilbm->Bmhd.w,Pic1.ilbm->Bmhd.h,0xC0,0xff,NULL);
  186.     LockLayerRom(Pic1.Win->RPort->Layer);
  187.     CopySBitMap(Pic1.Win->RPort->Layer);
  188.     UnlockLayerRom(Pic1.Win->RPort->Layer);
  189.     /* Resize gadgets and window (if too big)
  190.      * Window limits are reset and points
  191.      * redrawn with IDCMP_CHANGEWINDOW
  192.      */
  193.     SetGadgetAttrs(Pic1.BotGad, Pic1.Win, NULL,
  194.                         PGA_Total,    Pic1.ilbm->Bmhd.w,
  195.                         TAG_END);
  196.     SetGadgetAttrs(Pic1.SideGad, Pic1.Win, NULL,
  197.                         PGA_Total,    Pic1.ilbm->Bmhd.h,
  198.                         TAG_END);
  199.     ChangeWindowBox(Pic1.Win,Pic1.Win->LeftEdge,Pic1.Win->TopEdge,
  200.                          min(Pic1.Win->Width,Pic1.ilbm->Bmhd.w+Pic1.Screen->WBorLeft+SIZEIMAGE_W(n)),
  201.                          min(Pic1.Win->Height,Pic1.ilbm->Bmhd.h+Pic1.Screen->WBorTop + Pic1.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n)));
  202.     // Do the same of image/window2
  203.     BltBitMap(Pic2.ilbm->brbitmap,0,0,&(Pic2.BitMap),0,0,Pic2.ilbm->Bmhd.w,Pic2.ilbm->Bmhd.h,0xC0,0xff,NULL);
  204.     LockLayerRom(Pic2.Win->RPort->Layer);
  205.     CopySBitMap(Pic2.Win->RPort->Layer);
  206.     UnlockLayerRom(Pic2.Win->RPort->Layer);
  207.     SetGadgetAttrs(Pic2.BotGad, Pic2.Win, NULL,
  208.                         PGA_Total,    Pic2.ilbm->Bmhd.w,
  209.                         TAG_END);
  210.     SetGadgetAttrs(Pic2.SideGad, Pic2.Win, NULL,
  211.                         PGA_Total,    Pic2.ilbm->Bmhd.h,
  212.                         TAG_END);
  213.     ChangeWindowBox(Pic2.Win,Pic2.Win->LeftEdge,Pic2.Win->TopEdge,
  214.                          min(Pic2.Win->Width,Pic2.ilbm->Bmhd.w+Pic2.Screen->WBorLeft+SIZEIMAGE_W(n)),
  215.                          min(Pic2.Win->Height,Pic2.ilbm->Bmhd.h+Pic2.Screen->WBorTop + Pic2.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n)));
  216.     // Wait till its all done (why?) and reset Zoom
  217.     WaitBlit();
  218.     Zoom = 0;
  219. }
  220.  
  221. /* Zoom the image windows
  222.  * i.e. currently displayed 1x and
  223.  * want to display 2x
  224.  */
  225. void
  226. ReZoom(void) {
  227.     /* Currently normal size
  228.      * scale image 1, set window max size
  229.      * redo gadgets and copy to superbitmap
  230.      */
  231.     BitMapScale(&(Pic1.BitScaleArgs));
  232.     WindowLimits(Pic1.Win,0,0,(Pic1.ilbm->Bmhd.w<<1)+Pic1.Screen->WBorLeft+SIZEIMAGE_W(n),
  233.                     (Pic1.ilbm->Bmhd.h<<1)+Pic1.Screen->WBorTop + Pic1.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n));
  234.     SetGadgetAttrs(Pic1.BotGad, Pic1.Win, NULL,
  235.                         PGA_Total,    Pic1.ilbm->Bmhd.w<<1,
  236.                         TAG_END);
  237.     SetGadgetAttrs(Pic1.SideGad, Pic1.Win, NULL,
  238.                         PGA_Total,    Pic1.ilbm->Bmhd.h<<1,
  239.                         TAG_END);
  240.     LockLayerRom(Pic1.Win->RPort->Layer);
  241.     CopySBitMap(Pic1.Win->RPort->Layer);
  242.     UnlockLayerRom(Pic1.Win->RPort->Layer);
  243.     // Same for image 2
  244.     BitMapScale(&(Pic2.BitScaleArgs));
  245.     WindowLimits(Pic2.Win,0,0,(Pic2.ilbm->Bmhd.w<<1)+Pic2.Screen->WBorLeft+SIZEIMAGE_W(n),
  246.                     (Pic2.ilbm->Bmhd.h<<1)+Pic2.Screen->WBorTop + Pic2.Screen->Font->ta_YSize+1+SIZEIMAGE_H(n));
  247.     SetGadgetAttrs(Pic2.BotGad, Pic2.Win, NULL,
  248.                         PGA_Total,    Pic2.ilbm->Bmhd.w<<1,
  249.                         TAG_END);
  250.     SetGadgetAttrs(Pic2.SideGad, Pic2.Win, NULL,
  251.                         PGA_Total,    Pic2.ilbm->Bmhd.h<<1,
  252.                         TAG_END);
  253.     LockLayerRom(Pic2.Win->RPort->Layer);
  254.     CopySBitMap(Pic2.Win->RPort->Layer);
  255.     UnlockLayerRom(Pic2.Win->RPort->Layer);
  256.     /* Reset Zoom, Check new size gadgets,
  257.      * and redraw all the points
  258.      */
  259.     Zoom = 1;
  260.     doNewSize(&Pic1);
  261.     doNewSize(&Pic2);
  262.     DrawAllPoints();
  263. }
  264.  
  265. /* switch the check mark of a settings menu item
  266.  * Parameters: pos        position in the settings menu
  267.  *             settings   TRUE or FALSE
  268.  *             remove     remove and add menus? see UpdateSaveFormat()
  269.  */
  270. void
  271. SwitchMenuItem(UWORD pos,BOOL setting,BOOL remove) {
  272.     if (remove) {
  273.         RemoveMenus();
  274.     }
  275.     if (TSMorphWnd) {
  276.         if (setting) {
  277.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,pos,NOSUB)))->Flags |= CHECKED;
  278.         }
  279.         else {
  280.             (ItemAddress(TSMorphMenus,FULLMENUNUM(1,pos,NOSUB)))->Flags &= ~CHECKED;
  281.         }
  282.     }
  283.     if (ControlWindow) {
  284.         if (setting) {
  285.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,pos,NOSUB)))->Flags |= CHECKED;
  286.         }
  287.         else {
  288.             (ItemAddress(MyMenu,FULLMENUNUM(M_SETTINGS,pos,NOSUB)))->Flags &= ~CHECKED;
  289.         }
  290.     }
  291.     if (remove) {
  292.         AddMenus();
  293.     }
  294. }
  295.  
  296. /* Handle Settings menu messages
  297.  * Parameters: Selection   the item number
  298.  *             pic         the current picture
  299.  */
  300. void
  301. HandleSettings(UWORD Selection,struct Picture *pic) {
  302.     ULONG OZoom;    // The old zoom mode
  303.     // switch on the selection
  304.     switch(ITEMNUM(Selection)) {
  305.     case MM_ICONS:
  306.         // Toggle Create Icons?
  307.         CreateIcons = !CreateIcons;
  308.         SwitchMenuItem(MM_ICONS,CreateIcons,TRUE);
  309.         break;
  310.     case MM_PALETTE:
  311.         // Toggle Change Palette? - Uncolor the current image if we have one
  312.         if (palette && pic) {
  313.             UnColorWindow(pic);
  314.         }
  315.         palette = !palette;
  316.         SwitchMenuItem(MM_PALETTE,palette,TRUE);
  317.         break;
  318.     case MM_ZOOM:
  319.         // Toggle Zoom?
  320.         if (ControlWindow) {
  321.             // UnZoom or ReZoom the images if open
  322.             DisableWindows(DI_Zoom);
  323.             if (Zoom) {
  324.                 UnZoom();
  325.             }
  326.             else {
  327.                 ReZoom();
  328.             }
  329.             EnableWindows();
  330.         }
  331.         else {
  332.             if (Zoom) {
  333.                 Zoom = 0;
  334.             }
  335.             else {
  336.                 Zoom = 1;
  337.             }
  338.         }
  339.         SwitchMenuItem(MM_ZOOM,Zoom,TRUE);
  340.         break;
  341.     case MM_OPENMODE:
  342.         // Set new open mode
  343.         OpenMode = SUBNUM(Selection);
  344.         UpdateOpenMode(TRUE);
  345.         break;
  346.     case MM_SCREEN:
  347.         // Get public screen name
  348.         GetAString("Public Screen",ScreenName,H_P_PS);
  349.         break;
  350.     case MM_CUSTOM:
  351.         // Get custom screen mode
  352.         GetAString("Custom Screen Mode",CustomName,H_PCUSTM);
  353.         break;
  354.     case MM_CDEPTH:
  355.         // Get custom screen depth
  356.         GetANumber("Custom Screen Depth",&CustomDepth,H_PCUSTD);
  357.         break;
  358.     case MM_SPREVIEW:
  359.         // Get preview script
  360.         GetAString("Preview Script",PreviewScript,H_P_Preview);
  361.         break;
  362.     case MM_ICONSP:
  363.         // Toggle Create prefs Icons?
  364.         CreateIconsP = !CreateIconsP;
  365.         SwitchMenuItem(MM_ICONSP,CreateIconsP,TRUE);
  366.         break;
  367.     case MM_KEEPS:
  368.         // Toggle Keep Settings?
  369.         KeepSettings = !KeepSettings;
  370.         SwitchMenuItem(MM_KEEPS,KeepSettings,TRUE);
  371.     case MM_LOADS:
  372.         // Load new settings from requester
  373.         LoadSettings(NULL);
  374.         break;
  375.     case MM_SAVES:
  376.         // Save settings to ENV: and ENVARC:
  377.         SaveSettings("ENVARC:TSMorph/TSMorph.prefs");
  378.         SaveSettings("ENV:TSMorph/TSMorph.prefs");
  379.         break;
  380.     case MM_SAVESAS:
  381.         // save settings from requester
  382.         SaveSettings(NULL);
  383.         break;
  384.     case MM_ICONSR:
  385.         // Toggle Create render Icons?
  386.         CreateIconsR = !CreateIconsR;
  387.         SwitchMenuItem(MM_ICONSR,CreateIconsR,TRUE);
  388.         break;
  389.     case MM_DX:
  390.         // Get DX
  391.         GetANumber("DX",&DX,H_P_DX);
  392.         break;
  393.     case MM_DY:
  394.         // Get DY
  395.         GetANumber("DY",&DY,H_P_DY);
  396.         break;
  397.     case MM_LOADSCRIPT:
  398.         // Get load script
  399.         GetAString("Load Script",LoadScript,H_P_LS);
  400.         break;
  401.     case MM_PRESCRIPT:
  402.         // Get pre script
  403.         GetAString("Pre Script",PreScript,H_P_PES);
  404.         break;
  405.     case MM_POSTSCRIPT:
  406.         // Get post script
  407.         GetAString("Post Script",PostScript,H_P_POS);
  408.         break;
  409.     case MM_DEPTH:
  410.         // Get depth
  411.         GetANumber("Depth",&Depth,H_P_DE);
  412.         break;
  413.     case MM_RENDERMODE:
  414.         // Set new render mode
  415.         RenderMode = SUBNUM(Selection);
  416.         UpdateRenderMode(TRUE);
  417.         break;
  418.     case MM_SAVEFORMAT:
  419.         // Set new save format
  420.         SaveFormat = SUBNUM(Selection);
  421.         UpdateSaveFormat(TRUE);
  422.         break;
  423.     case MM_QUALITY:
  424.         // Get quality
  425.         GetANumber("Quality",&Quality,H_P_QU);
  426.         break;
  427.     case MM_SCREENR:
  428.         // Get render public screen
  429.         GetAString("Render Screen",ScreenNameR,H_P_PSR);
  430.         break;
  431.     case MM_ANTIALIAS:
  432.         // Toggle Anti-Alias?
  433.         AntiAlias = !AntiAlias;
  434.         SwitchMenuItem(MM_ANTIALIAS,AntiAlias,TRUE);
  435.         break;
  436.     case MM_RESETD:
  437.         // Reset to default prefs
  438.         OZoom = Zoom;    // keep current zoom
  439.         if (!ControlWindow) {
  440.             // if the images are open then we can not change these
  441.             PaletteAllowed = TRUE;
  442.             ZoomAllowed = TRUE;
  443.         }
  444.         // Set all other settings to defaults
  445.         ScreenName[0] = 0;
  446.         ScreenNameR[0] = 0;
  447.         CreateIcons = TRUE;
  448.         CreateIconsR = FALSE;
  449.         CreateIconsP = TRUE;
  450.         KeepSettings = TRUE;
  451.         if (PaletteAllowed) {
  452.             palette = TRUE;
  453.         }
  454.         else {
  455.             palette = FALSE;
  456.         }
  457.         Zoom = 0;
  458.         OpenMode = OPEN_ILBM_IF_COLOURS;
  459.         SaveFormat = MI_ILBM24;
  460.         Quality = 75;
  461.         strcpy(PreScript,"Rexx/Prescript");
  462.         strcpy(PostScript,"Rexx/Postscript");
  463.         strcpy(LoadScript,"Rexx/Loadscript");
  464.         strcpy(PreviewScript,"Rexx/Preview");
  465.         DX = 0;
  466.         DY = 0;
  467.         Depth = 2;
  468.         RenderMode = 0;
  469.         CustomName[0] = 0;
  470.         CustomDepth = 4;
  471.         UpdateParams(OZoom);
  472.         break;
  473.     case MM_LASTS:
  474.         // Load settings from ENVARC:
  475.         LoadSettings("ENVARC:TSMorph/TSMorph.prefs");
  476.         break;
  477.     case MM_RESTORE:
  478.         // Load settings from ENV:
  479.         LoadSettings("ENV:TSMorph/TSMorph.prefs");
  480.         break;
  481.     case MM_HELP:
  482.         // Toggle Help?
  483.         GHelp = !GHelp;
  484.         SwitchMenuItem(MM_HELP,GHelp,TRUE);
  485.         break;
  486.     default:
  487.         // something else ??
  488.         break;
  489.     }
  490. }
  491.  
  492. /* Request a number from the user using reqtools.library
  493.  * Parameters: title   - title of requester
  494.  *             number  - address of number to display and get
  495.  *             HelpNum - help key if help required
  496.  */
  497. void
  498. GetANumber(char *title,ULONG *number,ULONG HelpNum) {
  499.     ULONG                     ret = 2;    // current gadget
  500.     struct AmigaGuideMsg    *agm;        // amiga guide stuff
  501.     ULONG                     signals;    // signals to wait on
  502.     struct rtHandlerInfo    *rth;        // reqtools stuff
  503.     // disable all the windows
  504.     DisableWindows(HelpNum);
  505.     // loop until Ok or Cancel pressed
  506.     while (ret == 2) {
  507.         ret = CALL_HANDLER;
  508.         if (rtGetLong(number,title,NULL,
  509.                             RT_ReqHandler,        &rth,
  510.                             RT_Window,            TSMorphWnd,
  511.                             RTGL_ShowDefault,    TRUE,
  512.                             RT_Underscore,        '_',
  513.                             RTGL_GadFmt,         handle?"_OK|_Help|_Cancel":"_OK|_Cancel", // if amigaguide then help gadget
  514.                             TAG_END) == CALL_HANDLER) {
  515.             while (ret == CALL_HANDLER) {
  516.                 if (!rth->DoNotWait) {
  517.                     // wait if possible
  518.                     signals = Wait(rth->WaitMask | ASig);
  519.                 }
  520.                 ret = rtReqHandlerA(rth,signals,NULL);
  521.                 if (ret == 2) {
  522.                     // display help if requested, 2 is only possible if help gadget is available
  523.                     help(HelpNum);
  524.                 }
  525.                 if (signals & ASig) {
  526.                     // do amigaguide stuff
  527.                       while (agm = GetAmigaGuideMsg(handle)) {
  528.                          ReplyAmigaGuideMsg(agm);
  529.                      }
  530.                  }
  531.             }
  532.         }
  533.     }
  534.     // re-enable all the windows
  535.     EnableWindows();
  536. }
  537.  
  538. /* Request a string from the user using reqtools.library
  539.  * Parameters: title   - title of requester
  540.  *             number  - address of buffer to display and get
  541.  *             HelpNum - help key if help required
  542.  * See GetANumber for comments
  543.  */
  544. void
  545. GetAString(char *title,char *buffer,ULONG HelpNum) {
  546.     ULONG                     ret = 2;
  547.     struct AmigaGuideMsg    *agm;
  548.     ULONG                     signals;
  549.     struct rtHandlerInfo    *rth;
  550.     DisableWindows(HelpNum);
  551.     while (ret == 2) {
  552.         ret = CALL_HANDLER;
  553.         if (rtGetString(buffer,127,title,NULL,
  554.                             RT_ReqHandler,        &rth,
  555.                             RT_Window,            TSMorphWnd,
  556.                             RTGL_ShowDefault,    TRUE,
  557.                             RT_Underscore,     '_',
  558.                             RTGL_GadFmt,         handle?"_OK|_Help|_Cancel":"_OK|_Cancel",
  559.                             RTGS_AllowEmpty,    TRUE,
  560.                             TAG_END) == CALL_HANDLER) {
  561.             while (ret == CALL_HANDLER) {
  562.                 if (!rth->DoNotWait) {
  563.                     signals = Wait(rth->WaitMask | ASig);
  564.                 }
  565.                 ret = rtReqHandlerA(rth,signals,NULL);
  566.                 if (ret == 2) {
  567.                     help(HelpNum);
  568.                 }
  569.                 if (signals & ASig) {
  570.                       while (agm = GetAmigaGuideMsg(handle)) {
  571.                          ReplyAmigaGuideMsg(agm);
  572.                      }
  573.                  }
  574.             }
  575.         }
  576.     }
  577.     EnableWindows();
  578. }
  579.  
  580. /* Save the current settings
  581.  * Parameters: filename - filename to save to
  582.  *                        or NULL for requester
  583.  */
  584. void
  585. SaveSettings(char *filename) {
  586.     char    *ifilename = NULL;    // the actual file name
  587.     BPTR    fh;                        // file handle
  588.     BOOL    ok = TRUE;                // Is it working?
  589.     char    buffer[65];                // buffer for records
  590.     struct DiskObject *MyDiskObject;    // The Icon
  591.     // Disable all windows
  592.     DisableWindows(DI_WaitSS);
  593.     // if no file name supplied then request a name
  594.     if (!filename) {
  595.         if (GetAFile("TSMorph.prefs","Save Settings",FILF_SAVE)) {
  596.             ifilename = TempFilename;
  597.         }
  598.     }
  599.     else {
  600.         ifilename = filename;
  601.     }
  602.     // if we now a file name
  603.     if (ifilename) {
  604.         // try and open the file
  605.         if (fh = Open(ifilename,MODE_NEWFILE)) {
  606.             // save all TSMorph settings
  607.             FPuts(fh,";TSMorph parameters\n");
  608.             FPuts(fh,"CREATEICONS=");
  609.             FPuts(fh,CreateIcons?"YES\n":"NO\n");
  610.             FPuts(fh,"CHANGEPALETTE=");
  611.             FPuts(fh,(!PaletteAllowed)?"OFF\n":(palette?"YES\n":"NO\n"));
  612.             FPuts(fh,"ZOOM=");
  613.             FPuts(fh,(!ZoomAllowed)?"OFF\n":(Zoom?"YES\n":"NO\n"));
  614.             FPuts(fh,"OPENMODE=");
  615.             switch (OpenMode) {
  616.             case OPEN_ILBM_IF_ILBM:
  617.                 FPuts(fh,"IFILBM\n");
  618.                 break;
  619.             case OPEN_ILBM_ALWAYS:
  620.                 FPuts(fh,"ALWAYS\n");
  621.                 break;
  622.             case OPEN_REMAP:
  623.                 FPuts(fh,"REMAP\n");
  624.                 break;
  625.             case OPEN_OPAL:
  626.                 FPuts(fh,"OPAL\n");
  627.                 break;
  628.             case OPEN_ILBM_IF_COLOURS:
  629.             default:
  630.                 FPuts(fh,"IFCOLOURS\n");
  631.                 break;
  632.             }
  633.             if (*ScreenName) {
  634.                 FPuts(fh,"PUBSCREEN=");
  635.                 FPuts(fh,ScreenName);
  636.                 FPuts(fh,"\n");
  637.             }
  638.             else {
  639.                 FPuts(fh,";PUBSCREEN=\n");
  640.             }
  641.             if (*CustomName) {
  642.                 FPuts(fh,"CUSTOMMODE=");
  643.                 FPuts(fh,CustomName);
  644.                 FPuts(fh,"\n");
  645.             }
  646.             else {
  647.                 FPuts(fh,";CUSTOMMODE=\n");
  648.             }
  649.             sprintf(buffer,"CUSTOMDEPTH=%ld\n",CustomDepth);
  650.             FPuts(fh,buffer);
  651.             FPuts(fh,"PREVIEW=");
  652.             FPuts(fh,PreviewScript);
  653.             FPuts(fh,"\n");
  654.             FPuts(fh,"HELP=");
  655.             FPuts(fh,GHelp?"YES\n":"NO\n");
  656.             // Save all prefs settings
  657.             FPuts(fh,";Prefs parameters\n");
  658.             FPuts(fh,"CREATEICONSP=");
  659.             FPuts(fh,CreateIconsP?"YES\n":"NO\n");
  660.             FPuts(fh,"KEEPSETTINGS=");
  661.             FPuts(fh,KeepSettings?"YES\n":"NO\n");
  662.             // Save all render settings
  663.             FPuts(fh,";TSMorph-render parameters\n");
  664.             FPuts(fh,"CREATEICONSR=");
  665.             FPuts(fh,CreateIconsR?"YES\n":"NO\n");
  666.             sprintf(buffer,"DX=%ld\n",DX);
  667.             FPuts(fh,buffer);
  668.             sprintf(buffer,"DY=%ld\n",DY);
  669.             FPuts(fh,buffer);
  670.             FPuts(fh,"LOADSCRIPT=");
  671.             FPuts(fh,LoadScript);
  672.             FPuts(fh,"\n");
  673.             FPuts(fh,"PRESCRIPT=");
  674.             FPuts(fh,PreScript);
  675.             FPuts(fh,"\n");
  676.             FPuts(fh,"POSTSCRIPT=");
  677.             FPuts(fh,PostScript);
  678.             FPuts(fh,"\n");
  679.             sprintf(buffer,"DEPTH=%ld\n",Depth);
  680.             FPuts(fh,buffer);
  681.             sprintf(buffer,"MODE=%ld\n",RenderMode);
  682.             FPuts(fh,buffer);
  683.             FPuts(fh,"SAVEFORMAT=");
  684.             switch (SaveFormat) {
  685.             case MI_OPAL24:
  686.                 FPuts(fh,"OPAL24\n");
  687.                 break;
  688.             case MI_OPAL24T:
  689.                 FPuts(fh,"OPAL24T\n");
  690.                 break;
  691.             case MI_OPAL24F:
  692.                 FPuts(fh,"OPAL24F\n");
  693.                 break;
  694.             case MI_OPAL24FT:
  695.                 FPuts(fh,"OPAL24FT\n");
  696.                 break;
  697.             case MI_JPEG:
  698.                 FPuts(fh,"JPEG\n");
  699.                 break;
  700.             case MI_JPEGT:
  701.                 FPuts(fh,"JPEGT\n");
  702.                 break;
  703.             case MI_PBM:
  704.                 FPuts(fh,"PPM\n");
  705.                 break;
  706.             case MI_BW16:
  707.                 FPuts(fh,"BW16\n");
  708.                 break;
  709.             case MI_BW256:
  710.                 FPuts(fh,"BW256\n");
  711.                 break;
  712.             case MI_HAM6:
  713.                 FPuts(fh,"HAM6\n");
  714.                 break;
  715.             case MI_HAM8:
  716.                 FPuts(fh,"HAM8\n");
  717.                 break;
  718.             case MI_DCTV3:
  719.                 FPuts(fh,"DCTV3\n");
  720.                 break;
  721.             case MI_DCTV4:
  722.                 FPuts(fh,"DCTV4\n");
  723.                 break;
  724.             case MI_ILBM24:
  725.             default:
  726.                 FPuts(fh,"ILBM24\n");
  727.                 break;
  728.             }
  729.             sprintf(buffer,"QUALITY=%ld\n",Quality);
  730.             FPuts(fh,buffer);
  731.             if (*ScreenNameR) {
  732.                 FPuts(fh,"PUBSCREENR=");
  733.                 FPuts(fh,ScreenNameR);
  734.                 FPuts(fh,"\n");
  735.             }
  736.             else {
  737.                 FPuts(fh,";PUBSCREENR=\n");
  738.             }
  739.             FPuts(fh,"ANTIALIAS=");
  740.             FPuts(fh,AntiAlias?"YES\n":"NO\n");
  741.             // If want to save prefs Icon
  742.             if (CreateIconsP) {
  743.                 if (MyDiskObject = GetDiskObject(ifilename)) {
  744.                     // Icon already present so do not overwrite
  745.                     FreeDiskObject(MyDiskObject);
  746.                 }
  747.                 else {
  748.                     // Try and get an icon and write it
  749.                     if ((MyDiskObject = GetDiskObject("ENV:TSMorph/def_prefs")) ||
  750.                         (MyDiskObject = GetDiskObject("ENV:SYS/def_prefs")) ||
  751.                          (MyDiskObject = GetDefDiskObject(WBPROJECT))) {
  752.                         PutDiskObject(ifilename,MyDiskObject);
  753.                         FreeDiskObject(MyDiskObject);
  754.                     }
  755.                 }
  756.             }
  757.             // try and close the file
  758.             if (!Close(fh)) {
  759.                 ok = FALSE;
  760.             }
  761.         }
  762.         else {
  763.             ok = FALSE;
  764.         }
  765.     }
  766.     // enable the windows and display error if required
  767.     EnableWindows();
  768.     if (!ok) {
  769.         Error("Error Saving Settings '%s'","OK",ifilename,HE_SaveSettings);
  770.     }
  771. }
  772.  
  773. /* Load the current settings
  774.  * Parameters: filename - filename to load from
  775.  *                        or NULL for requester
  776.  */
  777. void
  778. LoadSettings(char *filename) {
  779.     BPTR    fh;                        // file handle
  780.     int     kount = 0;                // count of lines
  781.     int     kount1 = 0;                // index
  782.     BOOL    ok = TRUE;                // Still ok?
  783.     char    string[65];                // record buffer
  784.     char    *ifilename = NULL;    // actual filename
  785.     // if no file name then show requester
  786.     if (!filename) {
  787.         if (GetAFile("TSMorph.prefs","Load Settings",0)) {
  788.             ifilename = TempFilename;
  789.         }
  790.     }
  791.     else {
  792.         ifilename = filename;
  793.     }
  794.     // if we now have a file name...
  795.     // see Args.c MyArgArrayInit() for more info
  796.     if (ifilename) {
  797.         if (ArgArraySettings) {
  798.             FreeVec(ArgArraySettings);
  799.             ArgArraySettings = NULL;
  800.         }
  801.         if (fh = Open(ifilename,MODE_OLDFILE)) {
  802.             // If we have found a file the relevant lines
  803.             while (FGets(fh,string,64)) {
  804.                 if ((string[0] != '\n') &&
  805.                      (string[0] != ';')) {
  806.                     ++kount;
  807.                 }
  808.             }
  809.             Close(fh);
  810.             if (fh = Open(ifilename,MODE_OLDFILE)) {
  811.                 // Allocate memory for settings from file pointers
  812.                 if (ArgArraySettings = AllocVec((kount+1) * sizeof(UBYTE *),MEMF_CLEAR)) {
  813.                     // Read in all settings
  814.                     while (FGets(fh,string,64) &&
  815.                              (kount1 < kount)) {
  816.                         // remove newline
  817.                         string[strlen(string)-1] = '\0';
  818.                         // ignore blank and comment lines
  819.                         if (string[0] && (string[0]!=';')) {
  820.                             // Clone settings in memory
  821.                             ArgArraySettings[kount1] = strdup(string);
  822.                             ++kount1;
  823.                         }
  824.                     }
  825.                     // reset up the new settings
  826.                     InitParams(TRUE);
  827.                 }
  828.                 else {
  829.                     ok = FALSE;
  830.                 }
  831.                 Close(fh);
  832.             }
  833.             else {
  834.                 ok=FALSE;
  835.             }
  836.         }
  837.         else {
  838.             ok=FALSE;
  839.         }
  840.     }
  841.     if (!ok) {
  842.         Error("Error Loading Settings '%s'","OK",ifilename,HE_LoadSettings);
  843.     }
  844. }
  845.